package com.example.weather.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.weather.databinding.ItemAirQualityBinding
import com.example.weather.model.AirQualityItem

class AirQualityAdapter(
    private val items: List<AirQualityItem>
) : RecyclerView.Adapter<AirQualityAdapter.AirQualityViewHolder>() {

    class AirQualityViewHolder(
        private val binding: ItemAirQualityBinding
    ) : RecyclerView.ViewHolder(binding.root) {

        val imageView: ImageView = binding.iconImageView
        val titleTextView: TextView = binding.titleTextView
        val valueTextView: TextView = binding.valueTextView

        fun bind(item: AirQualityItem) {
            imageView.setImageResource(item.icon)
            titleTextView.text = item.title
            valueTextView.text = item.value
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AirQualityViewHolder {
        val binding = ItemAirQualityBinding.inflate(
            LayoutInflater.from(parent.context), 
            parent, 
            false
        )
        return AirQualityViewHolder(binding)
    }

    override fun onBindViewHolder(holder: AirQualityViewHolder, position: Int) {
        holder.bind(items[position])
    }

    override fun getItemCount(): Int = items.size
}